/*
 * Author  : Pallab
 * Program : 11391
 *
 * 2012-02-26 14:28:49
 * I have not failed, I have just found 10000 ways that won't work.
 *
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;


#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline int OR(int msk,int bit) {
    return ( msk|(1<<bit) );
}
inline int AND(int msk, int bit) {
    return ( msk&(1<<bit) );
}
inline int Clear(int msk, int bit) {
    return ( msk&(~(1<<bit)));
}
inline bool marked(int msk, int bit) {
    return ( AND(msk,bit)!=0 );
}
inline void debug(int _x) {
    cout<<_x<<'\n';
}
inline void debug(int _x,int _y) {
    cout<<_x<<' '<<_y<<'\n';
}
inline void debug(int _x,int _y,int _z) {
    cout<<_x<<' '<<_y<<' '<<_z<<'\n';
}
inline void debug(int _x,int _y,int _z,int _zz) {
    cout<<_x<<' '<<_y<<' '<<_z<<' '<<_zz<<'\n';
}
inline bool CI(int &_x) {
    return scanf("%d",&_x)==1;
}
inline bool CI(int &_x, int &_y) {
    return CI(_x)&&CI(_y) ;
}
inline bool CI(int &_x, int &_y, int &_z) {
    return CI(_x)&&CI(_y)&&CI(_z) ;
}
inline bool CI(int &_x, int &_y, int &_z, int &_zz) {
    return CI(_x)&&CI(_y)&&CI(_z)&&CI(_zz) ;
}

int R,C;
int nball;
int mask;
int bit[(1<<16)];

inline int encode(int rr, int cc) {
    return (rr*C)+cc;
}
inline void Read() {

    CI(R,C,nball);
    mask=0;
    int xx,yy;
    fo(i,nball) {
        CI(xx,yy);
        mask=OR(mask,encode(xx-1,yy-1));
    }
}
inline int bitcount(int msk) {
    return __builtin_popcount(msk);
}
inline void pre() {
    fo(i,1<<16) {
        bit[i]=bitcount(i);
    }
}
int rr[]= {-1,+1,+0,+0,-1,-1,+1,+1};
int cc[]= {+0,+0,+1,-1,-1,+1,+1,-1};

int dp[5][5][1<<17];

int go(int msk) {
    if (bit[msk]==1)return 1;
    int& nways=dp[R][C][msk];
    if (nways!=-1)return nways;

    nways=0;
    fo(i,R) {
        fo(j,C) {
            int v1=encode(i,j);
            if (marked(msk,v1)) {
                fo(k,8) {
                    int tr=i+rr[k];
                    int tc=j+cc[k];
                    int trr=i+(rr[k]<<1);
                    int tcc=j+(cc[k]<<1);
                    int v2=encode(tr,tc);
                    int v3=encode(trr,tcc);
                    if (tr>=0&&tc>=0&&trr>=0&&tcc>=0&&tr<R&&tc<C&&trr<R&&tcc<C&&marked(msk,v2)&&!marked(msk,v3)) {
                        nways+=go(OR(Clear( Clear(msk,v1) ,v2),v3));
                    }
                }
            }
        }
    }
    return nways;
}
inline void Proc() {

    /*
    for (int i=1;i<=4;++i) {
        for (int j=1;j<=4;++j) {
            R=i;
            C=j;
            int M=encode(R-1,C-1);
            mask=1<<M;
            for (int k=0;k<mask;++k) {
                int var = go(k);
                debug(R,C,var);
                sleep(1);
            }
        }
    }
    */
    int var = go(mask);
    cout<<var;
    puts("");
}
int main() {
    pre();
    SET(dp,-1);
    int tt;
    CI(tt);
    foE(i,1,tt) {
        Read();
        cout<<"Case "<<i<<": ";
        Proc();
    }

}
// kate: indent-mode cstyle; space-indent on; indent-width 0; 
